package com.gambi.tapestry.services.gwt;

import org.apache.tapestry5.EventContext;
import org.apache.tapestry5.runtime.ComponentEvent;

import com.gambi.tapestry.utils.GWTBoolean;

public class GWTWrappedComponentEvent implements ComponentEvent {

	private Object returnValue;

	private ComponentEvent componentEvent;

	public GWTWrappedComponentEvent(ComponentEvent componentEvent) {
		this.componentEvent = componentEvent;
	}

	@Override
	public Object coerceContext(int index, String desiredTypeName) {
		return componentEvent.coerceContext(index, desiredTypeName);
	}

	@Override
	public Object[] getContext() {
		return componentEvent.getContext();
	}

	@Override
	public EventContext getEventContext() {
		return componentEvent.getEventContext();
	}

	@Override
	public boolean matches(String eventType, String componentId,
			int parameterCount) {
		return componentEvent.matches(eventType, componentId, parameterCount);
	}

	@Override
	public boolean isAborted() {
		return true;
	}

	@Override
	public void setMethodDescription(String methodDescription) {
		componentEvent.setMethodDescription(methodDescription);
	}

	@Override
	public boolean storeResult(Object result) {
		if (result instanceof Boolean) {
			return componentEvent.storeResult(new GWTBoolean((Boolean) result));
		} else {
			return componentEvent.storeResult(result);
		}
	}

}
